package kd.hc.utils;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.serialization.DataEntitySerializer;
import kd.bos.dataentity.serialization.DataEntitySerializerOption;
import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.MainEntityType;

public class JsonUtil {
    public static String dyObjectToJsonStr(DynamicObject cacheObject) {
        DataEntitySerializerOption option = new DataEntitySerializerOption();
        option.setIncludeDataEntityState(false);
        option.setIncludeComplexProperty(true);
        option.setIncludeCollectionProperty(true);
        option.setIncludeType(false);
        String json = DataEntitySerializer.serializerToString(cacheObject, option);
        return json;
    }

    public static DynamicObject strToDyObject(String entityNumber, String jsonStr) {
        MainEntityType subMainType = EntityMetadataCache.getDataEntityType(entityNumber);
        DynamicObject dyn = (DynamicObject) DataEntitySerializer.deSerializerFromString(jsonStr, subMainType);
        return dyn;
    }

}
